//
//  WSGTabBarController.m
//  oneDollar
//
//  Created by Laki on 16/6/15.
//  Copyright © 2016年 com.Laki.corder. All rights reserved.
//

#import "WSGTabBarController.h"
#import "WSGNavigationController.h"

#import "WSGFoundController.h"
#import "WSGMeViewController.h"
#import "WSGHomePageController.h"
#import "WSGAnnouncedController.h"
#import "WSGPlayerKillingFieldController.h"

#import "WSGTabBar.h"
#import "UIImage+ImageOriginal.h"

@interface WSGTabBarController ()

@end

@implementation WSGTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加所有子控制器
    [self setUpAllControllView];
    
    // 设置自定义TabBar
    [self setTabBar];

}

#pragma mark --------------------
#pragma mark 添加所有子控制器
- (void)setUpAllControllView{
    // 首页
    [self setAddChild:[[WSGHomePageController alloc] init] title:@"青春1元购" image:[UIImage imageNamed:@"TabBar_HYGHall"] selectImage:[UIImage imageWithOriginal:[UIImage imageNamed:@"TabBar_HYGHall_selected"]]];
    
    // 最新揭晓
    [self setAddChild:[[WSGAnnouncedController alloc] init] title:@"最新揭晓" image:[UIImage imageNamed:@"TabBar_LastestAnnounce"] selectImage:[UIImage imageWithOriginal:[UIImage imageNamed:@"TabBar_LastestAnnounce_selected"]]];
    
    // PK场
    [self setAddChild:[[WSGPlayerKillingFieldController alloc] init] title:@"1元购PK场" image:[UIImage imageNamed:@"TabBar_HYG"] selectImage:[UIImage imageWithOriginal:[UIImage imageNamed:@"TabBar_HYG_selected"]]];
    
    // 发现
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:NSStringFromClass([WSGFoundController class]) bundle:nil];
    WSGFoundController *found = [storyBoard instantiateInitialViewController];
    [self setAddChild:found title:@"发现" image:[UIImage imageNamed:@"TabBar_Discovery"] selectImage:[UIImage imageWithOriginal:[UIImage imageNamed:@"TabBar_Discovery_selected"]]];
    
    // 我的
    [self setAddChild:[[WSGMeViewController alloc] init] title:@"我的" image:[UIImage imageNamed:@"TabBar_MyHYG"] selectImage:[UIImage imageWithOriginal:[UIImage imageNamed:@"TabBar_MyHYG_selected"]]];
}

/*
 * 添加控制器到导航控制器中,设置相关属性
 */
- (void)setAddChild:(UIViewController *)vc title:(NSString *)title image:(UIImage *)image selectImage:(UIImage *)selectImage{
    // 设置默认图片
    vc.tabBarItem.image = image;
    // 设置选中图片
    vc.tabBarItem.selectedImage = selectImage;
    // 设置导航栏标题文字
    vc.navigationItem.title = title;
    
    // 设置当前控制器为导航控制器的根控制器
    WSGNavigationController *nav = [[WSGNavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:nav];
}

#pragma mark --------------------
#pragma mark 设置自定义TabBar
- (void)setTabBar{
    WSGTabBar *tabBar = [[WSGTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];
}

@end
